<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>API: yuitest   ObjectAssert.js  (YUI Library)</title>
	<link rel="stylesheet" type="text/css" href="assets/api.css">
    <script type="text/javascript" src="assets/api-js"></script>
    <script type="text/javascript" src="assets/ac-js"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">

	<div id="hd">
        <a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
        <h3>yuitest&nbsp; <span class="subtitle">2.3.1</span></h3>
        <p>
        <a href="./index.html">Yahoo! UI Library</a> 
            &gt; <a href="./module_yuitest.html">yuitest</a>
                
                 &gt; ObjectAssert.js (source view) 
            </p>

	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form name="yui-classopts-form">
    <span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> Show Private</span>
    <span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> Show Protected</span>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 #classopts { display:none; }
                        </style>
<div class="highlight" ><pre><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">namespace</span><span class="o">(</span><span class="s2">&quot;util&quot;</span><span class="o">);</span>


<span class="c">//-----------------------------------------------------------------------------</span>
<span class="c">// ObjectAssert object</span>
<span class="c">//-----------------------------------------------------------------------------</span>
<span class="c"></span>
<span class="c">/**</span>
<span class="c"> * The ObjectAssert object provides functions to test JavaScript objects</span>
<span class="c"> * for a variety of cases.</span>
<span class="c"> *</span>
<span class="c"> * @namespace YAHOO.util</span>
<span class="c"> * @class ObjectAssert</span>
<span class="c"> * @static</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">ObjectAssert</span> <span class="o">=</span> <span class="o">{</span>
        
    <span class="c">/**</span>
<span class="c">     * Asserts that all properties in the object exist in another object.</span>
<span class="c">     * @param {Object} expected An object with the expected properties.</span>
<span class="c">     * @param {Object} actual An object with the actual properties.</span>
<span class="c">     * @param {String} message (Optional) The message to display if the assertion fails.</span>
<span class="c">     * @method propertiesAreEqual</span>
<span class="c">     * @static</span>
<span class="c">     */</span>
    <span class="nx">propertiesAreEqual</span> <span class="o">:</span> <span class="k">function</span> <span class="o">(</span><span class="nx">expected</span> <span class="c">/*:Object*/</span><span class="o">,</span> <span class="nx">actual</span> <span class="c">/*:Object*/</span><span class="o">,</span> 
                           <span class="nx">message</span> <span class="c">/*:String*/</span><span class="o">)</span> <span class="c">/*:Void*/</span> <span class="o">{</span>
        
        <span class="c">//get all properties in the object</span>
<span class="c"></span>        <span class="k">var</span> <span class="nx">properties</span> <span class="c">/*:Array*/</span> <span class="o">=</span> <span class="o">[];</span>        
        <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">property</span> <span class="k">in</span> <span class="nx">expected</span><span class="o">){</span>
            <span class="nx">properties</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">property</span><span class="o">);</span>
        <span class="o">}</span>
        
        <span class="c">//see if the properties are in the expected object</span>
<span class="c"></span>        <span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">properties</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span><span class="o">++){</span>
            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Assert</span><span class="o">.</span><span class="nx">isNotUndefined</span><span class="o">(</span><span class="nx">actual</span><span class="o">[</span><span class="nx">properties</span><span class="o">[</span><span class="nx">i</span><span class="o">]],</span> <span class="nx">message</span> <span class="o">||</span> 
                    <span class="s2">&quot;Property&#39;&quot;</span> <span class="o">+</span> <span class="nx">properties</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">+</span> <span class="s2">&quot;&#39; expected.&quot;</span><span class="o">);</span>
        <span class="o">}</span>

    <span class="o">},</span>
    
    <span class="c">/**</span>
<span class="c">     * Asserts that an object has a property with the given name.</span>
<span class="c">     * @param {String} propertyName The name of the property to test.</span>
<span class="c">     * @param {Object} object The object to search.</span>
<span class="c">     * @param {String} message (Optional) The message to display if the assertion fails.</span>
<span class="c">     * @method hasProperty</span>
<span class="c">     * @static</span>
<span class="c">     */</span>    
    <span class="nx">hasProperty</span> <span class="o">:</span> <span class="k">function</span> <span class="o">(</span><span class="nx">propertyName</span> <span class="c">/*:String*/</span><span class="o">,</span> <span class="nx">object</span> <span class="c">/*:Object*/</span><span class="o">,</span> <span class="nx">message</span> <span class="c">/*:String*/</span><span class="o">)</span> <span class="c">/*:Void*/</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">isUndefined</span><span class="o">(</span><span class="nx">object</span><span class="o">[</span><span class="nx">propertyName</span><span class="o">])){</span>
            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Assert</span><span class="o">.</span><span class="nx">fail</span><span class="o">(</span><span class="nx">message</span> <span class="o">||</span> 
                    <span class="s2">&quot;Property &quot;</span> <span class="o">+</span> <span class="nx">propertyName</span> <span class="o">+</span> <span class="s2">&quot; not found on object.&quot;</span><span class="o">);</span>
        <span class="o">}</span>    
    <span class="o">},</span>
    
    <span class="c">/**</span>
<span class="c">     * Asserts that a property with the given name exists on an object instance (not on its prototype).</span>
<span class="c">     * @param {String} propertyName The name of the property to test.</span>
<span class="c">     * @param {Object} object The object to search.</span>
<span class="c">     * @param {String} message (Optional) The message to display if the assertion fails.</span>
<span class="c">     * @method hasProperty</span>
<span class="c">     * @static</span>
<span class="c">     */</span>    
    <span class="nx">hasOwnProperty</span> <span class="o">:</span> <span class="k">function</span> <span class="o">(</span><span class="nx">propertyName</span> <span class="c">/*:String*/</span><span class="o">,</span> <span class="nx">object</span> <span class="c">/*:Object*/</span><span class="o">,</span> <span class="nx">message</span> <span class="c">/*:String*/</span><span class="o">)</span> <span class="c">/*:Void*/</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(!</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">lang</span><span class="o">.</span><span class="nx">hasOwnProperty</span><span class="o">(</span><span class="nx">object</span><span class="o">,</span> <span class="nx">propertyName</span><span class="o">)){</span>
            <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">util</span><span class="o">.</span><span class="nx">Assert</span><span class="o">.</span><span class="nx">fail</span><span class="o">(</span><span class="nx">message</span> <span class="o">||</span> 
                    <span class="s2">&quot;Property &quot;</span> <span class="o">+</span> <span class="nx">propertyName</span> <span class="o">+</span> <span class="s2">&quot; not found on object instance.&quot;</span><span class="o">);</span>
        <span class="o">}</span>     
    <span class="o">}</span>
<span class="o">};</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div class="module">
                        <h4>Modules</h4>
                        <ul class="content">

                                <li class=""><a href="module_animation.html">animation</a></li>

                                <li class=""><a href="module_autocomplete.html">autocomplete</a></li>

                                <li class=""><a href="module_button.html">button</a></li>

                                <li class=""><a href="module_calendar.html">calendar</a></li>

                                <li class=""><a href="module_colorpicker.html">colorpicker</a></li>

                                <li class=""><a href="module_connection.html">connection</a></li>

                                <li class=""><a href="module_container.html">container</a></li>

                                <li class=""><a href="module_datasource.html">datasource</a></li>

                                <li class=""><a href="module_datatable.html">datatable</a></li>

                                <li class=""><a href="module_dom.html">dom</a></li>

                                <li class=""><a href="module_dragdrop.html">dragdrop</a></li>

                                <li class=""><a href="module_editor.html">editor</a></li>

                                <li class=""><a href="module_element.html">element</a></li>

                                <li class=""><a href="module_event.html">event</a></li>

                                <li class=""><a href="module_history.html">history</a></li>

                                <li class=""><a href="module_imageloader.html">imageloader</a></li>

                                <li class=""><a href="module_logger.html">logger</a></li>

                                <li class=""><a href="module_menu.html">menu</a></li>

                                <li class=""><a href="module_slider.html">slider</a></li>

                                <li class=""><a href="module_tabview.html">tabview</a></li>

                                <li class=""><a href="module_treeview.html">treeview</a></li>

                                <li class=""><a href="module_yahoo.html">yahoo</a></li>

                                <li class=""><a href="module_yuiloader.html">yuiloader</a></li>

                                <li class="selected"><a href="module_yuitest.html">yuitest</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="YAHOO.tool.TestCase.html">YAHOO.tool.TestCase</a></li>
                                <li class=""><a href="YAHOO.tool.TestLogger.html">YAHOO.tool.TestLogger</a></li>
                                <li class=""><a href="YAHOO.tool.TestManager.html">YAHOO.tool.TestManager</a></li>
                                <li class=""><a href="YAHOO.tool.TestRunner.html">YAHOO.tool.TestRunner</a></li>
                                <li class=""><a href="YAHOO.tool.TestSuite.html">YAHOO.tool.TestSuite</a></li>
                                <li class=""><a href="YAHOO.util.ArrayAssert.html">YAHOO.util.ArrayAssert</a></li>
                                <li class=""><a href="YAHOO.util.Assert.html">YAHOO.util.Assert</a></li>
                                <li class=""><a href="YAHOO.util.AssertionError.html">YAHOO.util.AssertionError</a></li>
                                <li class=""><a href="YAHOO.util.ComparisonFailure.html">YAHOO.util.ComparisonFailure</a></li>
                                <li class=""><a href="YAHOO.util.DateAssert.html">YAHOO.util.DateAssert</a></li>
                                <li class=""><a href="YAHOO.util.ObjectAssert.html">YAHOO.util.ObjectAssert</a></li>
                                <li class=""><a href="YAHOO.util.ShouldError.html">YAHOO.util.ShouldError</a></li>
                                <li class=""><a href="YAHOO.util.ShouldFail.html">YAHOO.util.ShouldFail</a></li>
                                <li class=""><a href="YAHOO.util.UnexpectedError.html">YAHOO.util.UnexpectedError</a></li>
                                <li class=""><a href="YAHOO.util.UnexpectedValue.html">YAHOO.util.UnexpectedValue</a></li>
                                <li class=""><a href="YAHOO.util.UserAction.html">YAHOO.util.UserAction</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="ArrayAssert.js.html">ArrayAssert.js</a></li>
                                <li class=""><a href="Assert.js.html">Assert.js</a></li>
                                <li class=""><a href="DateAssert.js.html">DateAssert.js</a></li>
                                <li class="selected"><a href="ObjectAssert.js.html">ObjectAssert.js</a></li>
                                <li class=""><a href="TestCase.js.html">TestCase.js</a></li>
                                <li class=""><a href="TestLogger.js.html">TestLogger.js</a></li>
                                <li class=""><a href="TestManager.js.html">TestManager.js</a></li>
                                <li class=""><a href="TestRunner.js.html">TestRunner.js</a></li>
                                <li class=""><a href="TestSuite.js.html">TestSuite.js</a></li>
                                <li class=""><a href="UserAction.js.html">UserAction.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2007 Yahoo! Inc. All rights reserved.
	</div>
</div>
</body>
</html>
